package com.followme.module.gps;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.widget.Toast;

/**
 * Created with IntelliJ IDEA.
 * User: Kamil.O
 * Description: Service GPS location
 * Date: 24.11.13
 * Time: 02:45
 */
public class GPSTrackerBroadcastReceiver extends BroadcastReceiver {
    private static final String TAG_LOG_CAT = "MODULE_GPS";

    @Override
    public void onReceive(Context context, Intent intent) {
        String locationKey = LocationManager.KEY_LOCATION_CHANGED;
        String providerEnabledKey = LocationManager.KEY_PROVIDER_ENABLED;

        if (intent.hasExtra(providerEnabledKey)) {
            if (!intent.getBooleanExtra(providerEnabledKey, true)) {
                Toast.makeText(context, "Provider disabled", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(context, "Provider enabled", Toast.LENGTH_SHORT).show();
            }
        }

        if (intent.hasExtra(locationKey)) {
            Location loc = (Location)intent.getExtras().get(locationKey);
            Toast.makeText(context, "Location changed : Lat: " + loc.getLatitude() +" Lng: " + loc.getLongitude(),Toast.LENGTH_SHORT).show();
            //TODO: kolejne rzeczy

            Intent intentSend = new Intent("module.gps.send.coordinates");
            intent.putExtra("extra", "asdasd");
            context.sendBroadcast(intentSend);
        }
    }
}
